package algorithms;

import java.util.Arrays;
import java.util.List;
import java.util.Vector;

public class Common {
	public static List<List<String>> getAllSubsets(String[] input,
			int subSetsSize) {
		List<List<String>> result = new Vector<List<String>>();

		int size = input.length;

		if (subSetsSize > size)
			return null;

		if (subSetsSize == 1) {
			for (String string : input) {
				List<String> tmpV = new Vector<String>();
				tmpV.add(string);
				result.add(tmpV);
			}
			return result;
		}
		String currentElement;
		List<List<String>> tmpListOfList;
		for (int i = 0; i < size - 1; i++) {
			currentElement = input[i];
			tmpListOfList = getAllSubsets(Arrays.copyOfRange(input, i+1, size),
					subSetsSize - 1);
			if (tmpListOfList != null)
				for (List<String> list : tmpListOfList) {
					list.add(0,currentElement);
					result.add(list);
				}
		}

		return result;
	}
}
